package github._3y.algorithms;

import java.util.Arrays;

/**
 * @Author: DRevelation
 * @Date: 2021/1/20 19:53
 */
public class InsertSort {

    public static void main(String[] args) {
        int[] arr = new int[]{3, 1, 5, 2, 4};
        insertSort(arr);
        System.out.println("=======================");
        System.out.println("arr = " + Arrays.toString(arr));
    }

    private static void insertSort(int[] arr) {
        int temp;
        for (int i = 1; i < arr.length; i++) {
            temp = arr[i];
            int j = i - 1;
            while (j >= 0 && arr[j] > temp) {
                arr[j + 1] = arr[j];
                j--;
            }
            arr[j + 1] = temp;
            System.out.println("arr = " + Arrays.toString(arr));
        }
    }

}
